package cn.com.dhcc.app.pub.core.job.monitor;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.base.IocBean;
import cn.com.dhcc.app.core.exception.NiceException;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.consts.AppConst;
import cn.com.dhcc.turbo.entity.registry.NodeInfo;
import cn.com.dhcc.turbo.service.monitor.MonitorService;
import cn.com.dhcc.turbo.service.registry.BaseInfoService;
/**
 * 告警处理
 * @author qiao
 * @2014-6-10 @上午9:24:18
 */
public class MonitorHandlerCronJob extends StatefulMethodInvokingJob{
	@SuppressWarnings("deprecation")
	Logger logger = Log.getExistLogger(LOGTYPE.MONITOR);
	@Override
	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {
		logger.info("["+AppConst.installIp+"]"+"定时任务MonitorHandlerCronJob开始执行...."); 
		BaseInfoService baseInfoService=(BaseInfoService) CM.getBeanByName(IocBean.BASE_INFO_SERVICEIMPL_BEAN);
		NodeInfo localNode;
		try {
			localNode = baseInfoService.getCurrentNodeInfo();
			if (localNode==null) {
				return;
			}
		} catch (ServiceException e) {
			logger.error("获取本节点信息失败:"+e);
		}
		MonitorService service = CM.getBean(MonitorService.class);
		try {
			//告警计算
			service.monitorOnTimeValueHandle();
		} catch (NiceException e) {
			logger.error(e);
		}
		//指标同步
		service.syncToNodes();
		//告警处理
		service.autoHhandlerAlert();
		logger.info("["+AppConst.installIp+"]"+"定时任务MonitorHandlerCronJob执行结束...."); 
	}

	
}
